/**
 * ClassName: CustomerList
 * Package: PACKAGE_NAME
 * Description:
 *
 * @Author fjorid
 * @Create 2025/2/20 21:24
 * @Version 1.0
 */
public class CustomerList {
    private Customer[] customers;
    private int total = 0;

    public CustomerList(int totalCustomer) {
        customers = new Customer[totalCustomer];
    }

    public boolean addCustomer(Customer customer) {
        if (total < customers.length) {
            customers[total] = customer;
            total++;
            return true;
        }
        return false;
    }

    public boolean replaceCustomer(int index, Customer cust) {
        if (index >= 0 && index < total) {
            customers[index] = cust;
            return true;
        }
        return false;
    }

    public boolean deleteCustomer(int index) {
        if (index >= 0 && index < total) {
            for (int i = index; i < total - 1; i++) {
                customers[i] = customers[i + 1];
            }
            customers[total - 1] = null;
            total--;
            return true;
        }
        return false;
    }

    public Customer[] getAllCustomers() {
        Customer[] result = new Customer[total];
        for (int i = 0; i < total; i++) {
            result[i] = customers[i];
        }
        return result;
    }

    public Customer getCustomer(int index) {
        if (index >= 0 && index < total) {
            return customers[index];
        }
        return null;
    }

    public int getTotal() {
        return total;
    }
}